/*
 * Comparisor.h
 *
 *  Created on: Aug 14, 2013
 *      Author: jeff
 */

#ifndef COMPARISOR_H_
#define COMPARISOR_H_

#include <stdio.h>

#include <string>

#include <json/json.h>

#define CHUNK_SIZE		(1024)

#define JSON_KEY_SEGMENT		"segments"
#define JSON_KEY_OFFSET			"offset"
#define JSON_KEY_DELETE_LENGTH	"delete_length"
#define JSON_KEY_INSERT_LENGTH	"insert_length"
#define JSON_KEY_OUTPUT			"output"
#define JSON_KEY_HASH			"HASH"

class Comparisor {
private:
	long compare_from_left;
	long comare_from_right;
	long offset_left;
	long offset_right;

protected:
	int find_first_diff(const char* left, const char* right, long long size, int *delete_length, int *insert_length, char **insert_buffer);
	void save_diff_info(int offset, int delete_length, int insert_length, const char * diff, Json::Value* segment);
	virtual void output_diff_data(int insert_length, const char * diff, Json::Value* segment);

public:
	Comparisor();
	virtual ~Comparisor(){};

	long chunk_size;

	void diff(const char* left, int left_size, const char* right, int right_size, Json::Value* result);
};

#endif /* COMPARISOR_H_ */
